import request from "@/utils/request";

// 物料查询
export function queryMaterial(data) {
  return request({
    url: "/md/material/queryForCode",
    method: "get",
    params: data,
  });
}

// IOT数据采集
export function getIotData(data) {
  return request({
    url: "/iot/data/real-time",
    method: "get",
    params: data,
  });
}

// 供应商查询
export function querySuppliers(data) {
  return request({
    url: "/md/supplier/page",
    method: "get",
    params: data,
  });
}

// 仓库列表查询
export function getWarehouseList() {
  return request({
    url: "/md/warehouse/list",
    method: "get",
  });
}

// 创建完整入库单（新API）
export function createCompletePoStockIn(data) {
  return request({
    url: "/wm/po-stock-in-main/create-complete",
    method: "post",
    data,
  });
}

// 创建入库单（旧API，保留兼容性）
export function createInWarehouseOrder(data) {
  return request({
    url: "/wm/in-warehouse-order/create",
    method: "post",
    data,
  });
}

// 获取入库单号
export function generateInWarehouseCode() {
  return request({
    url: "/wm/in-warehouse-order/generate-code",
    method: "get",
  });
}

// 批量保存入库明细
export function batchSaveInWarehouseDetail(data) {
  return request({
    url: "/wm/in-warehouse-order-detail/batch-save",
    method: "post",
    data,
  });
}

// 采购合同查询（用于合同匹配）
export function queryPoContractDetail(data) {
  return request({
    url: "/mm/po-contract-detail/page",
    method: "get",
    params: data,
  });
}

// 检斤数据查询
export function queryWeighMid(data) {
  return request({
    url: "/mm/meter/page",
    method: "get",
    params: data,
  });
}

//查询入库记录
export function queryStockInDetail(data) {
  return request({
    url: "/wm/po-stock-in-main/po-stock-in/page",
    method: "get",
    params: data,
  });
}

// API映射对象
const api = {
  queryWeighMid,
  queryPoContractDetail,
  queryMaterial,
  querySuppliers,
  getWarehouseList,
  createCompletePoStockIn,
  createInWarehouseOrder,
  generateInWarehouseCode,
  queryStockInDetail,
  batchSaveInWarehouseDetail,
};

export default api;
